<?php

class articles{
    
    private $vue;
    private $mysql;
    
    public function __construct() {
        require_once 'modeles/modele.php';
        $this->mysql = new ModeleArticles();
    }
    
    public function afficherDonneesArticle(){

        $this->vue = $this->mysql->selectListeArticle("articles", "*");
        
        require_once 'vues/vue.php';
    }
    
    public function ModifierDonneesArticle($id){
        
        
        
        $this->vue = $this->mysql->selectUnArticle("articles", "*",$id);
        
        require_once 'vues/vue_modifier.php';
    }
    
    public function UpdateDonneesArticle($id){
        $titre = isset($_POST["titre"]) ? $_POST["titre"] : "";
        $contenu = isset($_POST["contenu"]) ? $_POST["contenu"] : "";
        
        $tab[] = array("titre", $titre);
        $tab[] = array("contenu", $contenu);
        
       
        
        $this->vue = $this->mysql->UpdateUnArticle("articles", $id, $tab);
        $this->vue = $this->mysql->selectUnArticle("articles", "*",$id);
        require_once 'vues/vue_modifier.php';
    }
    

    // CONTROLEUR SUPPRESSION ARTICLE

    public function effacerDonneesArticle($idArticle) {

        $idArticle = isset($_GET["idArticle"]) ? $_GET["idArticle"] : "";
        
        $this->vue = $this->mysql->supprimerArticle("articles", "ID");

        require_once 'vues/vue.php';
    }

}
